#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=300;
typedef long long LL;

LL a[maxn],dp[maxn];
int main(void)
{
  cin.tie(0);std::ios::sync_with_stdio(false);
  LL n,m;cin>>n>>m;
  for(LL i=1;i<=n;i++){
    cin>>a[i];
  }

  memset(dp,0x3f,sizeof(dp));
  LL minx=1e18;
  ///dp[1]=a[1];
  for(LL i=1;i<=m;i++){
    dp[i]=a[i];
  }
  for(LL i=m+1;i<=n;i++){
     for(LL j=i-m;j<=i-1;j++){
        dp[i]=min(dp[j]+a[i],dp[i]);
     }
  }
 /*(
  for(LL i=1;i<=n;i++){
    cout<<dp[i]<<" ";
  }
  cout<<endl;
 */
  LL ans=1e18;
  for(LL i=n;i>=n-m+1;i--){
    ans=min(ans,dp[i]);
  }
  cout<<ans<<endl;
return 0;
}
